<template>
	<view class="wrap">
		<view class="top"></view>
		<view class="content">
			<view class="title">欢迎登录吉大购</view>
			<input class="u-border-bottom"  v-model="email" placeholder="请输入邮箱号" />
			<input class="u-border-bottom"  v-model="password" placeholder="请输入密码" />
			<!-- <view class="tips">未注册的手机号验证后自动创建吉大购账号</view> -->
			<button @tap="submit" :style="[inputStyle]" class="getCaptcha">登录</button>
			<view class="alternative">
				<view class="password">找回密码</view>
				<view class="issue" @click="register">注册账号</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			email: '',
			password: '',
		}
	},
	computed: {
		inputStyle() {
			let style = {};
			//手机号验证  密码不为空验证  密码只能是英文或数字验证
			if(uni.$u.test.email(this.email) && !uni.$u.test.isEmpty(this.password)) {
				style.color = "#fff";
				style.backgroundColor = this.$u.color['warning'];
			}
			return style;
		}
	},
	async onLoad() {
	},
	methods: {
		async submit() {
			if(!uni.$u.test.email(this.email) || uni.$u.test.isEmpty(this.password)) return;
			const params = {
				email: this.email,
				password: this.password,
			}
			const loginRes = await uni.$u.api.authLogin(params);
			//提示登陆成功
			this.$u.toast('登陆成功');
			//缓存token
			uni.$u.vuex("vuex_token",loginRes.access_token);
			//缓存用户信息
			const userInfo = await this.$u.api.userInfo();
			uni.$u.vuex("vuex_user",userInfo);
			
			//登录之后跳转到来源页
			const backUrl = uni.getStorageSync("backUrl") || 'page/index/index'; //当backUrl返回的时候也报错
			setTimeout(()=>{
				uni.$u.route({
					type: 'reLaunch',
					url: backUrl,
				});
			},1000);
		},
		register(){
			console.log("注册跳转");
			uni.$u.route({
				type: 'navigateTo',
				url: 'pages/auth/register/register',
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.wrap {
	font-size: 28rpx;
	.content {
		width: 600rpx;
		margin: 80rpx auto 0;
		
		.u-border-bottom{
			margin-top: 30rpx;
		}
		.title {
			text-align: left;
			font-size: 60rpx;
			font-weight: 500;
			margin-bottom: 100rpx;
		}
		input {
			text-align: left;
			margin-bottom: 10rpx;
			padding-bottom: 6rpx;
		}
		.tips {
			color: $u-info;
			margin-bottom: 60rpx;
			margin-top: 8rpx;
		}
		.getCaptcha {
			background-color: rgb(253, 243, 208);
			color: $u-tips-color;
			border: none;
			font-size: 30rpx;
			padding: 12rpx 0;
			margin-top: 30rpx;
			
			&::after {
				border: none;
			}
		}
		.alternative {
			color: $u-tips-color;
			display: flex;
			justify-content: space-between;
			margin-top: 30rpx;
		}
	}
	.buttom {
		.loginType {
			display: flex;
			padding: 350rpx 150rpx 150rpx 150rpx;
			justify-content:space-between;
			
			.item {
				display: flex;
				flex-direction: column;
				align-items: center;
				color: $u-content-color;
				font-size: 28rpx;
			}
		}
		
		.hint {
			padding: 20rpx 40rpx;
			font-size: 20rpx;
			color: $u-tips-color;
			
			.link {
				color: $u-warning;
			}
		}
	}
}
</style>
